from dataclasses import dataclass
from datetime import datetime
from typing import Optional

@dataclass
class EmailPendingTask:
    """Domain entity for email pending task"""
    id: Optional[int] = None
    email_id: str = ""
    task_id: str = ""
    email_info_json: Optional[str] = None
    sop_json: Optional[str] = None
    generated_reply: Optional[str] = None
    action_type: Optional[str] = None
    created_at: Optional[datetime] = None
    created_by: Optional[str] = None
    
    def __post_init__(self):
        """Validate the entity after initialization"""
        if not self.email_id:
            raise ValueError("email_id cannot be empty")
        if not self.task_id:
            raise ValueError("task_id cannot be empty")
        
        # Set created_at to current time if not provided
        if self.created_at is None:
            self.created_at = datetime.now()
        
        # Set created_by to default if not provided
        if self.created_by is None:
            self.created_by = "system"